How do I convert python time.gmtime() to MongoDB Date
Question: I need to convert the time returned by gmtime() to a readable string. As a
mistake, I populated huge data in mongo and stored date as a string. After the
discussion in my [previous
question](http://stackoverflow.com/questions/33015162/how-do-i-fetch-all-
mongo-data-which-is-created-greater-than-a-particular-
date/33015994?noredirect=1#comment53886215_33015994) I am just doing a regex
match to get the relevant data from mongo. The problem now is to convert
gmtime which is say:

    
    
    time.struct_time(tm_year=2015, tm_mon=10, tm_mday=9, tm_hour=9, tm_min=49, tm_sec=31, tm_wday=4, tm_yday=282, tm_isdst=0)
    

to this:

    
    
    Tue 27 Jan 2015
    

This is the string format that is stored in mongo

    
    
    {
        "startTime" : "Sun 25 Jan 2015 07:14:26 GMT",
        "endTime" : "",
        "jobStatus" : "JOBCANCELLED",
        "uiState" : "HISTORY",
        "priority" : "SILVER"
    }
    

Dumb way to make Mongo query work:

    
    
    db.getCollection('jobsCollection').find({"startTime":{$regex: "Tue 27 Jan 2015.*"}})
    

I need to convert the gmtime to the regex attribute shown in the mongo query

Is there any way I can achieve this?


Answer: 
    import time
    print time.gmtime(123456)
    print time.strftime("%A %d-%b-%Y", time.gmtime(time.time()))
    >>>Friday 09-Oct-2015
    

