Filtering by dates from gcloud CLI

4,047 views
Skip to first unread message

Lee Cordwainer

unread,
Oct 17, 2017, 7:40:38 PM10/17/17
to Google Cloud Developers
Hello,


I'm having trouble following the instructions from "gcloud topic filters"
which are duplicated on this page https://cloud.google.com/sdk/gcloud/reference/topic/filters
and also duplicated in a blog post https://cloudplatform.googleblog.com/2016/06/filtering-and-formatting-fun-with.html


The example given says:

 $ gcloud projects list \
      --format="table(projectNumber,projectId,createTime)" \
      --filter="createTime.date('%Y-%m-%d', Z)='2016-05-11'"

But when running that exact command, or any variation of it, I get the error message:

ERROR: (gcloud.projects.list) Term expected [createTime.date('%Y-%m-%d', Z) *HERE* ='2016-05-11'].



I've tried using other operators than = and varying combinations of single and double quotes to rule out shell interpretations/expansions.


It feels like the syntax has changed since the documentation was created. I'm currently using gcloud CLI version 170.0.1 and can move forward/backward with some flexibility if needed.
I am trying obtain a list of snapshots filtered by creationTime and not getting very far. Also it is confusing that different parts of the API use `createTime` and others use `creationTimestamp`.


-Lee

Fady (Google Cloud Platform)

unread,
Oct 18, 2017, 12:08:11 AM10/18/17
to Google Cloud Developers
Hello Lee, 

I have reproduced the exact same error. I will look into this error further more tomorrow as to find the exact syntax. Hence, we can update the documentation. 

Thank you for reporting this, I’ll update you by the end of the day tomorrow.

Fady (Google Cloud Platform)

unread,
Oct 19, 2017, 12:01:08 AM10/19/17
to Google Cloud Developers

I have reached the backend team to give us feedback about the correct syntax. I will keep monitoring this thread and will update you by Friday. 

Fady (Google Cloud Platform)

unread,
Oct 20, 2017, 10:31:47 PM10/20/17
to google-c...@googlegroups.com
Hello Lee, 

The backend team verified that the functionality is not supported anymore. On the other hand, while I was testing on my end I managed to list the projects created on a specific date. But, I couldn't list all projects after a specific date. 

gcloud projects list --format="table(projectNumber,projectId,createTime.date('%Y-%m-%d', Z))" --filter=2015-12-11

Therefore, I submitted an issue to have the document reviewed and corrected. However, if the above command does not help in your use case about snapshots, please submit a feature request on this link, and include all relevant details about your use case, like the exact command, or HTTP request  for listing the snapshots. Thank you again for reporting this.

Lee Cordwainer

unread,
Oct 23, 2017, 2:08:10 PM10/23/17
to Google Cloud Developers
The syntax that worked for filtering snapshots, for anyone else who comes across this thread, was to drop the transformation function.  It works with all the various comparison operators.

e.g.

gcloud compute snapshots list --filter="labels.whatever=abcdef AND creationTimestamp<'2017-10-05'"

-Lee
Reply all
Reply to author
Forward
0 new messages